package com.demo.controller;

import com.demo.common.Result;
import com.demo.pojo.Student;
import com.demo.service.StudentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student")
@RequiredArgsConstructor
public class StudentController {
    private final StudentService studentService;

    /**
     * 查询单个学生
     * @param studentId
     * @return
     */
    @GetMapping("/search/{Id}")
    public Result GetOneStudent(@PathVariable("Id") Integer studentId) {
        return studentService.GetOne(studentId);
    }
    /**
     * 查询所有学生信息
     * @return
     */
    @GetMapping("/search/all")
    public Result GetAllStudent() {
        return studentService.GetAll();
    }

    /**
     * 新建单个学生
     * @param student
     * @return
     */
    @PostMapping("/create/One")
    public Result NewAStudent(@RequestBody Student student) {
        return studentService.NewAStudent(student);
    }

    /**
     * 删除单个学生
     * @param studentId
     * @return
     */
    @PostMapping("/delete/{Id}")
    public Result Delete(@PathVariable("Id") Integer studentId) {
        return studentService.deleteOne(studentId);
    }

    /**
     * 修改学生数据
     * @param student
     * @return
     */
    @PostMapping("/edit")
    public Result Edit(@RequestBody Student student) {
        return studentService.editOne(student);
    }

}
